package com.fly.service.Impl;

import com.fly.bean.Resources;
import com.fly.bean.RoleReRela;
import com.fly.mapper.PermissionMapper;
import com.fly.service.PermissionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class PermissionServiceImpl implements PermissionService {

    @Resource
    private PermissionMapper permissionMapper;

    /**
     * 根据用户ID获取角色ID
     *
     * @param userId
     * @return
     */
    @Override
    public Integer selectRoleIdByUserId(Integer userId) {
        return permissionMapper.selectRoleIdByUserId(userId);
    }

    /**
     * 根据角色ID得到资源id信息
     *
     * @param roleId
     * @return
     */
    @Override
    public Integer[] selectResourcesIdByRoleId(Integer roleId) {
        return permissionMapper.selectResourcesIdByRoleId(roleId);
    }

    /**
     * 根据资源id获取其对应的所有资源信息
     *
     * @param resourcesId
     * @return
     */
    @Override
    public Resources selectResourcesByResourcesId(Integer resourcesId) {
        return permissionMapper.selectResourcesByResourcesId(resourcesId);
    }

    /**
     * 根据角色名称查询角色Id
     *
     * @param roleName
     * @return
     */
    @Override
    public Integer selectRoleIdByRoleName(String roleName) {
        return permissionMapper.selectRoleIdByRoleName(roleName);
    }

    /**
     * 根据父节点名称得到资源类型ResourcesType
     *
     * @param resourcesName
     * @return
     */
    @Override
    public Integer selectResourcesTypeResourcesName(String resourcesName) {
        return permissionMapper.selectResourcesTypeResourcesName(resourcesName);
    }

    /**
     * 根据父节点名称得到ResourcesId
     *
     * @param resourcesName
     * @return
     */
    @Override
    public Integer selectResourcesIdByResourcesName(String resourcesName) {
        return permissionMapper.selectResourcesIdByResourcesName(resourcesName);
    }

    /**
     * 通过父节点的resourcesId得到其子节点的数量
     *
     * @param resourcesId
     * @return
     */
    @Override
    public Integer selectCountByResourcesId(Integer resourcesId) {
        return permissionMapper.selectCountByResourcesId(resourcesId);
    }

    /**
     * 查询资源状态信息根据sysProValueName
     *
     * @param sysProValueName
     * @return
     */
    @Override
    public Integer selectResourcesStateBySysProValueName(String sysProValueName) {
        return permissionMapper.selectResourcesStateBySysProValueName(sysProValueName);
    }

    /**
     * 通过父节点，功能名称，功能URL，和状态添加菜单节点
     *
     * @param resources
     * @return
     */
    @Override
    public Integer addResources(Resources resources) {
        return permissionMapper.addResources(resources);
    }

    /**
     * 根据角色Id删除其对应的角色资源关系信息
     *
     * @param roleId
     * @return
     */
    @Override
    public Integer deleteRoleAndResourcesByRoleId(Integer roleId) {
        return permissionMapper.deleteRoleAndResourcesByRoleId(roleId);
    }

    /**
     * 根据所选中的资源名称得到对应的资源Id
     *
     * @param resourcesName
     * @return
     */
    @Override
    public Integer selectResourcesIdByResourcesName2(String resourcesName) {
        return permissionMapper.selectResourcesIdByResourcesName2(resourcesName);
    }

    /**
     * 根据角色Id和资源Id添加role_resources_relation数据
     *
     * @param roleReRela
     * @return
     */
    @Override
    public Integer addRole_resources_relation(RoleReRela roleReRela) {
        return permissionMapper.addRole_resources_relation(roleReRela);
    }

    /**
     * 查询得到所有的角色名称
     *
     * @return
     */
    @Override
    public String[] selectAllRoleName() {
        return permissionMapper.selectAllRoleName();
    }

    @Override
    public String[] selectRoleRequestURI(int roleId) {
        return permissionMapper.selectRoleRequestURI(roleId);
    }
}
